home *** CD-ROM | disk | FTP | other *** search
/ Lattice ISP Synario Start… & ISP Encyclopedia 1997 / LATTICE Synario.iso / ispcode / gds / pregasm.awk < prev    next >
Encoding:
AWK Script  |  1993-09-15  |  1.2 KB  |  45 lines

  1. # $Log: pregasm.awk $
  2. # Revision 1.2  1993/09/15  18:28:42  Mike_Lottridge
  3. # enhance handling of inversions for labels
  4. #
  5.  
  6. function process_inv( ){
  7.   
  8.   # count "!"
  9.   # if odd # of "!" found, change "=" to "!="
  10.   # if even # of "!", strip all of them out
  11.  
  12.   num_excl=split($0,dum,"!")-1;
  13.   if ( (num_excl%2)==0)gsub("!",""); #even number of inversions
  14.   else {                             #odd number of inversions
  15.      gsub("!",""); # remove all "!"
  16.      gsub("=","!=");
  17.   }
  18. }
  19.  
  20. BEGIN {
  21.   cmt_re="^[ ]*\".*";   # reg expression for comment line
  22. }
  23.  
  24. $0 ~ /.*=.*/ && $1 !~ cmt_re { process_inv(); # fix up any inversions 
  25. }
  26.  
  27. {
  28.   if ((NF == 3) && ($1 !~ cmt_re) && ($2 ~ /[Pp][Ii][Nn]/)) { 
  29.      # this is a symbolic pin assignment of the form <name> pin <pin number>
  30.      if($1 ~ /\!.*/)symbol[substr($1,2)]="!pin" $3;
  31.      else symbol[$1]="pin " $3;
  32.   
  33.   }
  34.   else if (($1 !~ cmt_re) && (($2 ~ /=|!=/)||($3 ~ /=|!=/))) {
  35.      if ($1 in symbol) $1 = symbol[$1];   
  36.      if ($3 in symbol) $3 = symbol[$3];
  37.      if ($4 in symbol) $4 = symbol[$4];
  38.      process_inv(); # process any new inversions that may have appeared
  39.      print $0;
  40.   }
  41.   else print $0;
  42.  
  43.  
  44. }
  45.